package com.yygo.model;

import com.yygo.model.enums.FeedbackStatus;
import com.yygo.model.enums.FeedbackType;
import com.yygo.model.enums.RequestStatus;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by tiansha on 2015/6/13.
 */
@Entity
@Table(name = "feedback")
public class Feedback extends BaseObject {

    private static final long serialVersionUID = -1771333545278149464L;
    private Long id;
    private RequestStatus reqStatus;

    private FeedbackType feedbackType;
    private User feedbackRequester;
    private User feedbackTarget;
    private FeedbackStatus feedbackStatus;

    private String readableStatus;
    private Date time;
    private String content;

    private boolean requireBack;

    private LoanRequest loanRequest;
    private Long reqId;

    public Feedback() {}

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "req_status", length = 50)
    @Enumerated(EnumType.STRING)
    public RequestStatus getReqStatus() {
        return reqStatus;
    }

    public void setReqStatus(RequestStatus reqStatus) {
        this.reqStatus = reqStatus;
    }

    @Column(name = "feedback_type", length = 50)
    @Enumerated(EnumType.STRING)
    public FeedbackType getFeedbackType() {
        return feedbackType;
    }

    @Column(name = "feedback_status", length = 50)
    @Enumerated(EnumType.STRING)
    public void setFeedbackType(FeedbackType feedbackType) {
        this.feedbackType = feedbackType;
    }

    public FeedbackStatus getFeedbackStatus() {
        return feedbackStatus;
    }

    public void setFeedbackStatus(FeedbackStatus feedbackStatus) {
        this.feedbackStatus = feedbackStatus;
    }

    @Column(name = "time")
    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Column(name = "content")
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Column(name = "require_back")
    public boolean isRequireBack() {
        return requireBack;
    }

    public void setRequireBack(boolean requireBack) {
        this.requireBack = requireBack;
    }

    @ManyToOne
    @JoinColumn(name="req_id")
    public LoanRequest getLoanRequest() {
        return loanRequest;
    }

    public void setLoanRequest(LoanRequest loanRequest) {
        this.loanRequest = loanRequest;
    }

    @Transient
    public String getReadableStatus() {
        return readableStatus;
    }

    public void setReadableStatus(String readableStatus) {
        this.readableStatus = readableStatus;
    }

    @Transient
    public Long getReqId() {
        return reqId;
    }

    public void setReqId(Long reqId) {
        this.reqId = reqId;
    }

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="requester_user_id")
    public User getFeedbackRequester() {
        return feedbackRequester;
    }

    public void setFeedbackRequester(User feedbackRequester) {
        this.feedbackRequester = feedbackRequester;
    }

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="target_user_id")
    public User getFeedbackTarget() {
        return feedbackTarget;
    }

    public void setFeedbackTarget(User feedbackTarget) {
        this.feedbackTarget = feedbackTarget;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Feedback feedback = (Feedback) o;

        if (id.equals(feedback.id)) {
            return true;
        }

        return false;
    }

    public int hashCode() {
        int result = 3;
        result = 57 * result + (id != null ? id.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "Feedback{" +
                "id=" + id +
                '}';
    }
}
